/*
Janet Putnam
CS 362
Assignment 3
Unit Test 4 - Unit Test of getCost

Include the following lines in make file:

unittest4:  unittest4.c dominion.o rngs.o
	gcc -o unittest4 -g unittest4.c dominion.o rngs.o $(CFLAGS)

*/

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>


/* Copy of function from dominion.c for reference purposes, can be removed from code
int getCost(int cardNumber)
{
  switch( cardNumber ) 
    {
    case curse:
      return 0;
    case estate:
      return 2;
    case duchy:
      return 5;
    case province:
      return 8;
    case copper:
      return 0;
    case silver:
      return 3;
    case gold:
      return 6;
    case adventurer:
      return 6;
    case council_room:
      return 5;
    case feast:
      return 4;
    case gardens:
      return 4;
    case mine:
      return 5;
    case remodel:
      return 4;
    case smithy:
      return 4;
    case village:
      return 3;
    case baron:
      return 4;
    case great_hall:
      return 3;
    case minion:
      return 5;
    case steward:
      return 3;
    case tribute:
      return 5;
    case ambassador:
      return 3;
    case cutpurse:
      return 4;
    case embargo: 
      return 2;
    case outpost:
      return 5;
    case salvager:
      return 4;
    case sea_hag:
      return 4;
    case treasure_map:
      return 4;
    }
	
  return -1;
}
*/

int getCost(int cardNumber);

int getCostTest(int print_pass)
{
	int i;
	int r;
	int value;
	
	for(i = 0; i < 100; i++)
	{
		r=(rand()%27);
		printf("Card #:  %d\n", r);
		value = getCost(r);
		if (r==0)
		{
			if(value == 0)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Curse card correctly returned value of 0.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Curse card should return value of 0.  Value returned = %d.\n", i, value);
			}
		}
		else if (r==1)
		{
			if(value == 2)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Estate card correctly returned value of 2.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Estate card should return value of 2.  Value returned = %d.\n", i, value);
			}		
		}
		else if (r==2)
		{
			if(value == 5)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Duchy card correctly returned value of 5.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Duchy card should return value of 5.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==3)
		{
			if(value == 8)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Province card correctly returned value of 8.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Province card should return value of 8.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==4)
		{
			if(value == 0)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Copper card correctly returned value of 0.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Copper card should return value of 0.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==5)
		{
			if(value == 3)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Silver card correctly returned value of 3.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Silver card should return value of 3.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==6)
		{
			if(value == 6)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Gold card correctly returned value of 6.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Gold card should return value of 6.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==7)
		{
			if(value == 6)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Adventurer card correctly returned value of 6.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Adventurer card should return value of 6.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==8)
		{
			if(value == 5)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Council room card correctly returned value of 5.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Council room card should return value of 5.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==9)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Feast card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Feast card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==10)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Gardens card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Gardens card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==11)
		{
			if(value == 5)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Mine card correctly returned value of 5.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Mine card should return value of 5.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==12)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Remodel card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Remodel card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==13)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Smithy card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Smithy card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==14)
		{
			if(value == 3)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Village card correctly returned value of 3.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Village card should return value of 3.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==15)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Baron card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Baron card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==16)
		{
			if(value == 3)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Great hall card correctly returned value of 3.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Great hall card should return value of 3.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==17)
		{
			if(value == 5)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Minion card correctly returned value of 5.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Minion card should return value of 5.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==18)
		{
			if(value == 3)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Steward card correctly returned value of 3.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Steward card should return value of 3.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==19)
		{
			if(value == 5)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Tribute card correctly returned value of 5.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Tribute card should return value of 5.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==20)
		{
			if(value == 3)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Ambassador card correctly returned value of 3.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Ambassador card should return value of 3.  Value returned = %d.\n", i, value);
			}			
		}		
		else if (r==21)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Cutpurse card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Cutpurse card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==22)
		{
			if(value == 2)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Embargo card correctly returned value of 2.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Embargo card should return value of 2.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==23)
		{
			if(value == 5)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Outpost card correctly returned value of 5.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Outpost card should return value of 5.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==24)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Salvager card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Salvager card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==25)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Sea hag card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Sea hag card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else if (r==26)
		{
			if(value == 4)
			{
				if(print_pass ==0)
				{
					printf("PASS:  Test %d - Treasure map card correctly returned value of 4.\n", i);
				}
			}
			else
			{
				printf("FAIL:  Test %d - Treasure map card should return value of 4.  Value returned = %d.\n", i, value);
			}			
		}
		else
		{
			printf("Error - issue with randon number normalization.");
		}
	
	}
	
	
	return 0;


}


int main(int argc, char **argv)
{	
	int print_pass;
	//if print_pass = 0, then results will print for passing tests.
	//if print_pass = 1, then results will not print for passing tests.
	//regardless of print_pass state, failing tests will print results.
	
	print_pass = atoi(argv[1]);
	if ((print_pass != 1 ) || (print_pass != 0))
	{
		print_pass = 0;
	}
	srand(time(NULL));
	getCostTest(print_pass);
	return 0;
}

